import 'package:flutter/material.dart';

// void main() {
//   runApp(const AnimatedThemePage());
// }

class AnimatedThemePage extends StatefulWidget {
  const AnimatedThemePage({super.key});

  @override
  State<AnimatedThemePage> createState() => _AnimatedThemePageState();
}

class _AnimatedThemePageState extends State<AnimatedThemePage> {
  bool _isDark = false;

  @override
  Widget build(BuildContext context) {
    return AnimatedTheme(
      data: _isDark ? ThemeData.dark() : ThemeData.light(),
      duration: const Duration(milliseconds: 500),
      curve: Curves.easeInOut,
      child: Builder(
        builder: (context) {
          return MaterialApp(
            theme: Theme.of(context),
            home: Scaffold(
              appBar: AppBar(title: const Text("AnimatedTheme 案例")),
              body: Center(
                child: ElevatedButton(
                  onPressed: () {
                    setState(() {
                      _isDark = !_isDark;
                    });
                  },
                  child: Text(_isDark ? "切换到浅色主题" : "切换到深色主题"),
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}
